package com.qianfeng.smartdevice.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.pagehelper.PageInfo;
import com.qianfeng.smartdevice.dto.R;
import com.qianfeng.smartdevice.pojo.Devices;
import com.qianfeng.smartdevice.service.IDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/devices")
public class DeviceController {
    @Autowired
    private IDeviceService deviceService;

    @GetMapping("/devices")
    public R findAllDevices(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit) {
        PageInfo<Devices> pageInfo = deviceService.findAllDevice(page, limit);
        return R.setOk(pageInfo);
    }

    @PostMapping("/command/{uuid}/{command}")
    public R sendControl(@PathVariable String uuid,@PathVariable String command) throws JsonProcessingException {
        deviceService.sendContro(uuid,command);
        return R.setOk(null);
    }

}
